﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace KOPLibrary.Forms.CashFlow
{
    public partial class MultipleFlowForm : Form
    {
        public MultipleFlowForm()
        {
            InitializeComponent();
        }

        public int Execute(Cacheflow.CacheflowDs ds, BindingSource source, string dataMember, KOPLibrary.Cacheflow.CacheflowDs.HareketRow row)
        {            
            ctlUnit.SelectedIndex = 2;
            ctlStartDate.Value = row.Tarih;
            ctlFinishDate.Value = new DateTime(ctlStartDate.Value.Year, 12, 31);
            DateTime endDate = ctlFinishDate.Value.AddHours(23).AddMinutes(59).AddSeconds(59);
            int count = 0;
            bool result = ShowDialog() == System.Windows.Forms.DialogResult.OK;

            if (result)
            {
                DateTime tarih = ctlStartDate.Value;
                
                while(tarih < endDate)
                {
                    switch (ctlUnit.SelectedIndex)
                    {
                        case 0:
                            {
                                tarih = tarih.AddDays(1);
                                break;
                            }
                        case 1:
                            {
                                tarih = tarih.AddDays(7);
                                break;
                            }
                        case 2:
                            {
                                tarih = tarih.AddMonths(1);
                                break;
                            }
                        case 3:
                            {
                                tarih = tarih.AddMonths(3);
                                break;
                            }
                        case 4:
                            {
                                tarih = tarih.AddMonths(4);
                                break;
                            }
                        case 5:
                            {
                                tarih = tarih.AddYears(1);
                                break;
                            }
                    }
                    if (tarih > endDate)
                        break;
                    KOPLibrary.Cacheflow.CacheflowDs.HareketRow r = ds.Hareket.NewHareketRow();
                    r.ItemArray = row.ItemArray;
                    r.ID = Guid.NewGuid();
                    r.Tarih = tarih;
                    ds.Hareket.AddHareketRow(r);
                    count++;
                }
                
            }

            return count;
        }

        private void ctlOK_Click(object sender, EventArgs e)
        {
            if (Util.Confirm("İşleme devam etmek istiyor musunuz ?"))
                DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        private void messageControl1_Load(object sender, EventArgs e)
        {

        }
    }
}
